package com.scott.spring.ch11.service;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @author 黄后林
 * @version 1.0
 * @date 2021-12-15 09:27:43
 */
public class RoleService implements InitializingBean, DisposableBean {


    public RoleService() {
        System.out.println("--------执行ch11#RoleService--------");
    }

    //1
    @PostConstruct
    public void postConstruct()  {
        System.out.println("--------执行ch11#postConstruct--------");
    }

    //2
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("--------执行ch11#afterPropertiesSet--------");
    }

    //3
    public void initMethod()  {
        System.out.println("--------执行ch11#initMethod--------");
    }

    // 业务方法
    public int add(int x ,int y){
        System.out.println("--------执行ch11#add--------");
        int sum = x+y;
        return sum;
    }

    // 1、容器关闭前执行
    @PreDestroy
    public void preDestroy() {
        System.out.println("--------执行ch11#preDestroy--------");
    }

    // 2、容器关闭前执行
    @Override
    public void destroy() throws Exception {
        System.out.println("--------执行ch11#destroy--------");
    }

    // 3、容器关闭前执行
    public void destroyMethod()  {
        System.out.println("--------执行ch11#destroyMethod--------");
    }


}
